<%@ Page Language="C#" MasterPageFile="SecondPage.master" CodeFile="ShowAd.aspx.cs"
    Inherits="ShowAd_aspx" Title="Show Ad" %>

<%@ Register TagPrefix="uc1" TagName="CategoryDropDown" Src="Controls/CategoryDropDown.ascx" %>
<%@ Register TagPrefix="uc1" TagName="CategoryPath" Src="Controls/CategoryPath.ascx" %>
<%@ Import Namespace="AspNet.StarterKits.Classifieds.Web" %>
<%@ Register src="Controls/AdvancedSearch.ascx" tagname="AdvancedSearch" tagprefix="uc1" %>
<asp:Content ID="SecondBarContent" ContentPlaceHolderID="SecondBar" runat="server">
    <%--<div id="crumbs_text">
        <uc1:CategoryPath ID="CategoryPath" Runat="server" OnCategorySelectionChanged="CategoryPath_CategorySelectionChanged" /></div>--%>
</asp:Content>
<asp:Content ID="MainContent" ContentPlaceHolderID="Main" runat="server">
    <div class="navigate">
           <%-- <p>
                <span>Houses:</span>&nbsp;<span><b>London</b></span>
            </p>--%>
        </div>
        <div class="crumb">
            <uc1:CategoryPath ID="CategoryPath" runat="server" OnCategorySelectionChanged="CategoryPath_CategorySelectionChanged" />
        </div>
    <div class="detail-bound">
    <div class="detail">
        
        <asp:Repeater ID="AdDetails" runat="server" DataSourceID="AdsDataSource" OnItemDataBound="AdDetails_ItemDataBound">
            <ItemTemplate>
                <div style="display: none">
                    <!--bo di tam thoi-->
                    <asp:HyperLink ID="URLLink" runat="server" Target="_blank" />
                    <asp:Label ID="AdIdLabel" runat="server" Text='<%# Eval("Id") %>'></asp:Label>
                    <asp:HyperLink ID="PostByLink" runat="server" NavigateUrl='<%# Eval("MemberName", "Search.aspx?member={0}") %>'
                        Text='<%# Eval("MemberName") %>' />
                    <asp:Label ID="ExpirationLabel" runat="server"></asp:Label>
                </div>
                <h2>
                    <%#Eval("title") %>
                </h2>
                <p>
                    <span class="price">
                        <%#String.Format("&#163;{0:#,###,###.00}", Eval("Price")) %></span><span class="location"><asp:Label
                            ID="LocationLabel" runat="server" Text='<%# Eval("Location") %>'></asp:Label></span></p>
                <div class="attributes">
                    <img src="app_themes/default/images/p_right_bullet.png" />
                    <span class="key">Date available:</span>
                    <asp:Label ID="DateAddedLabel" runat="server" Text='<%# Eval("ExpirationDate", "{0:D}") %>'></asp:Label>
                    <img src="app_themes/default/images/p_right_bullet.png" class="img-pad" />
                    <span class="key">Category:</span>
                    <asp:Label ID="CategoryNameLabel" runat="server" Text='<%# Eval("CategoryName") %>'></asp:Label>
                    <img src="app_themes/default/images/p_right_bullet.png" class="img-pad" />
                    <span class="key">Type:</span>
                    <asp:Label ID="AdStatusLabel" runat="server" Text='<%# OutputFormatting.AdTypeToString(Eval("AdType")) %>'></asp:Label>
                </div>                
            </ItemTemplate>
        </asp:Repeater>
        <div class="content float-left">
                    <div class='textbox'>
                        <asp:Label ID="DescriptionLabel" runat="server" Text='<%# Eval("Description") %>'></asp:Label>
                    </div>
                    <div class="clear">
                    </div>
                    <ul class="link">
                       
                    <asp:PlaceHolder ID="AdActions" runat="server">
                        <li>
                            <asp:LinkButton ID="RespondButton" runat="server" OnClick="RespondButton_Click">Respond to Ad</asp:LinkButton></li>
                        <li>
                            <asp:LinkButton ID="EmailAdButton" runat="server" OnClick="EmailAdButton_Click">Send Ad as Email</asp:LinkButton></li>
                        <li>
                            <asp:LinkButton ID="SaveAdButton" runat="server" OnClick="SaveAdButton_Click">Save Ad as Bookmark</asp:LinkButton></li>
                    </asp:PlaceHolder>
                    <asp:PlaceHolder ID="AdNotActivePanel" runat="server" Visible="false">
                        <li><strong>This Ad is currently<br />
                            not active.</strong></li></asp:PlaceHolder>
                
                    </ul>
                    <div class="clear separator">
                        <strong>Ad Reference:</strong> If you can not find information as contact detail, please go to the source link to get information <asp:HyperLink ID="adUrl" runat=server Visible="false">Click here</asp:HyperLink><br />
                        <%--<strong>Ad type:</strong> Agency<br />--%>
                        <strong>Posted:</strong> <asp:Label ID="posted" runat="server" /><br />
                        <strong>Viewed:</strong> <asp:Label ID="numViews" runat="server" /> times<br />
                    </div>
                    <div class="clear"></div>
                    <asp:Panel ID="AdDetailsPanel" runat="server">
                        <h4>
                            <asp:Label ID="AdTitleLabel" runat="server" Visible="false"></asp:Label></h4>
                        <h5 style="display: none">
                            <asp:Label ID="AdTypeLabel" runat="server" />:
                            <asp:Label ID="AdPriceLabel" runat="server" /></h5>
                        <asp:Panel ID="PhotoPanel" runat="server" Visible="False">
                            <p class="notice">
                                <asp:LinkButton ID="HidePhotoPanel" runat="server" OnClick="HidePhotoPanel_Click">Hide again</asp:LinkButton></p>
                            <p>
                                <asp:ImageButton ID="FullSizePhoto" runat="server" OnClick="FullSizePhoto_Click"
                                    AlternateText="Show other ad photos if they exist." /></p>
                        </asp:Panel>
                        <asp:Panel ID="ResponsePanel" runat="server" Visible="False">
                            <h5 class="action">
                                Respond to Ad:</h5>
                            Your Contact Name:<br />
                            <asp:TextBox ID="ResponseContactNameTextBox" runat="server" CssClass="user_info"></asp:TextBox>
                            <p>
                                Your Contact Email (used for replies)<br />
                                <asp:TextBox ID="ResponseContactEmailTextBox" runat="server" CssClass="user_info"></asp:TextBox>
                                <asp:RequiredFieldValidator runat="server" ControlToValidate="ResponseContactEmailTextBox"
                                    ErrorMessage="A contact email is required." ValidationGroup="RespondPanelGroup"
                                    ToolTip="A contact email is required." ID="ResponseEmailRequired1" Display="dynamic">
                                </asp:RequiredFieldValidator>
                                <asp:RegularExpressionValidator runat="server" ControlToValidate="ResponseContactEmailTextBox"
                                    ValidationExpression=".*@.*\..*" ErrorMessage="A valid email is required." ToolTip="A valid email is required."
                                    ID="ResponseEmailRequired2" Display="dynamic">
                                </asp:RegularExpressionValidator>
                            </p>
                            <p>
                                Comments or Questions:<br />
                                <asp:TextBox ID="ResponseCommentsTextBox" runat="server" TextMode="MultiLine" Width="452px"
                                    Height="123px"></asp:TextBox></p>
                            <p>
                                <asp:Button ID="ResponseSubmitButton" runat="server" Text="Submit" OnClick="ResponseSubmitButton_Click" />
                                <asp:Button ID="CancelResponseButton" runat="server" Text="Cancel" OnClick="CancelResponseButton_Click" />
                            </p>
                        </asp:Panel>
                        <asp:Panel ID="EmailPanel" runat="server" Visible="false">
                            <h5 class="action">
                                Send Ad as Email:</h5>
                            <p>
                                Your Name:<br />
                                <asp:TextBox ID="EmailSenderNameTextBox" runat="server" CssClass="user_info"></asp:TextBox>
                            </p>
                            <p>
                                Your Email:<br />
                                <asp:TextBox ID="EmailSenderAddressTextBox" runat="server" CssClass="user_info"></asp:TextBox>
                                <asp:RequiredFieldValidator runat="server" ControlToValidate="EmailSenderAddressTextBox"
                                    ErrorMessage="A sender email is required." ValidationGroup="EmailPanelGroup"
                                    ToolTip="A sender email is required." ID="EmailSenderAddressTextBoxValidator1"
                                    Display="Dynamic">
                                </asp:RequiredFieldValidator>
                                <asp:RegularExpressionValidator runat="server" ControlToValidate="EmailSenderAddressTextBox"
                                    ValidationExpression=".*@.*\..*" ErrorMessage="A valid email is required." ToolTip="A valid email is required."
                                    ID="EmailSenderAddressTextBoxValidator2" Display="Dynamic">
                                </asp:RegularExpressionValidator>
                            </p>
                            <p>
                                Send to (Recipient Email):<br />
                                <asp:TextBox ID="EmailRecipientAddressTextBox" runat="server" CssClass="user_info"></asp:TextBox>
                                <asp:RequiredFieldValidator runat="server" ControlToValidate="EmailRecipientAddressTextBox"
                                    ErrorMessage="A recipient email is required." ValidationGroup="EmailPanelGroup"
                                    ToolTip="A recipient email is required." ID="EmailRecipientAddressTextBoxValidator1"
                                    Display="Dynamic">
                                </asp:RequiredFieldValidator>
                                <asp:RegularExpressionValidator runat="server" ControlToValidate="EmailRecipientAddressTextBox"
                                    ValidationExpression=".*@.*\..*" ErrorMessage="A valid email is required." ToolTip="A valid email is required."
                                    ID="EmailRecipientAddressTextBoxValidator2" Display="Dynamic">
                                </asp:RegularExpressionValidator>
                            </p>
                            <p>
                                Subject:<br />
                                <asp:TextBox ID="EmailSubjectTextBox" runat="server" Width="452px" CssClass="user_info"></asp:TextBox>
                            </p>
                            <p>
                                Message:<br />
                                <asp:TextBox ID="EmailMessageTextBox" runat="server" TextMode="MultiLine" Width="452px"
                                    Height="123px"></asp:TextBox></p>
                            <p>
                                &nbsp;<asp:Button ID="EmailSubmitButton" runat="server" Text="Submit" OnClick="EmailSubmitButton_Click" />
                                <asp:Button ID="CancelEmailButton" runat="server" Text="Cancel" OnClick="CancelEmailButton_Click" />
                            </p>
                        </asp:Panel>
                        <asp:Panel ID="AdSavedPanel" runat="server" Visible="False" EnableViewState="False">
                            <p style="text-align: center;" class="notice">
                                <span>The Ad has been <a href="MyAds.aspx?saved=1">saved to your list of Bookmarks.</a></span></p>
                        </asp:Panel>
                        <asp:Panel ID="EmailSentPanel" runat="server" Visible="False" EnableViewState="False">
                            <p class="notice" style="text-align: center;">
                                <span>The email was sent successfully.</span></p>
                        </asp:Panel>
                        <asp:Panel ID="EmailNotSentPanel" runat="server" Visible="False" EnableViewState="False">
                            <p class="notice" style="text-align: center; font-weight: bold;">
                                <span>The email was not sent. Contact the system administrator for further details.</span></p>
                        </asp:Panel>
                    </asp:Panel>
                </div>
                <div class="right float-right">
                    <div class="main-img">
                        <div>
                            <div>
                                <div>                                   
                                    <asp:Repeater ID="MainPhotoSlide" runat="Server" 
                                        DataSourceID="PhotosDataSource" onitemdatabound="MainPhotoSlide_ItemDataBound">
                                        <ItemTemplate>                                            
                                            <asp:HyperLink ID="HyperLink" runat="server" NavigateUrl='<%# Eval("Id", "PhotoDisplay.ashx?photoid={0}&size=full") %>' CssClass="vlightbox">
                                                <img alt="Enlarge Photo" src='<%# Eval("Id", "PhotoDisplay.ashx?photoid={0}&size=full") %>'
                                                     />
                                                     <strong>Enlarge picture</strong>
                                            </asp:HyperLink>
                                        </ItemTemplate>
                                    </asp:Repeater>
                                    <script language="javascript" src="js/visuallightbox.js" type="text/javascript" ></script>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="small-img">              
                        
                        <asp:Repeater  ID="PhotoList" runat="Server"
                        DataSourceID="PhotosDataSource"> 
                        <ItemTemplate>                               
                                <a href="<%# Eval("Id", "PhotoDisplay.ashx?photoid={0}&size=full") %>" class="small-img-switch">                                
                                <img alt="Enlarge Photo" src='<%# Eval("Id", "PhotoDisplay.ashx?photoid={0}&size=medium") %>' class="float-left" />
                                 </a>                                
                        </ItemTemplate>
                    </asp:Repeater>
                        <div class="clear">
                        </div>
                    </div>
                    <div class="map">
                        <a href="javascript:void(0)" id='show_map' datafld='<%=this.fullAddress %>' rel='<%=this.addressToGeo %>'>
                        
                        <asp:Image runat="server" ID='imgMap' Width='325px' Height='240px' />                        
                        <p class="icon">Enlarge map</p>
                        </a>
                    </div>
                </div>
                <div class="clear">
                </div>
                </div>
                <div class="recent-item-text">Recent ads in this category</div>
        <div class="recent-item">
            
            
                        <asp:Repeater ID="adsRepeater" runat="server" DataSourceID="AdSearchDataSource" 
                            onitemdatabound="adsRepeater_ItemDataBound">
                            <%--<ItemTemplate>
                                <div class="item float-left">
                                    <asp:Image AlternateText="Ad Preview photo" ImageUrl='<%#String.Format("~/PhotoDisplay.ashx?photoid={0}&amp;size=medium", Eval("PreviewImageId")) %>'
                                        ID="image" runat="server" />
                                    <h3>
                                        <%#String.Format("&#163;{0:#,###,###.00}", Eval("Price")) %>
                                    </h3>
                                    <p>
                                        <asp:HiddenField ID="idHidden" runat="server" Value='<%#Eval("Id") %>' />
                                        <asp:HyperLink  runat="server" ID="link" CssClass="hastip" 
                                            ToolTip='<%#Eval("Title") %>' 
                                            NavigateUrl='<%#String.Format("~/ShowAd.aspx?id={0}", Eval("id")) %>'><%#Eval("Title").ToString().Substring(0, Eval("Title").ToString().Length > 45 ? 45 : Eval("Title").ToString().Length)%>...</asp:HyperLink>
                                    </p>
                                    <span class="location">
                                        <%# OutputFormatting.AdTypeToString(Eval("AdType")) %></span><br />
                                    <span class="time">Posted:
                                        <%#String.Format("{0:dd/MM/yy}", Eval("DateCreated")) %></span>
                                </div>
                            </ItemTemplate>--%>
                            <ItemTemplate>
                                <div class="item float-left">
                                    <a href='<%#String.Format("ShowAd.aspx?id={0}", Eval("id")) %>' rel='<%#String.Format("ajaxTooltip.aspx?q={0}", Eval("id")) %>' class="hastip" title='<%#Eval("Title") %>'>
                                    <asp:Image AlternateText="Ad Preview photo" ImageUrl='<%#String.Format("~/PhotoDisplay.ashx?photoid={0}&amp;size=medium", Eval("PreviewImageId")) %>'
                                        ID="image" runat="server"  />
                                        </a>
                                    <h3>
                                        <%#String.Format("&#163;{0:#,###,###.00}", Eval("Price")) %>
                                    </h3>
                                    <p>
                                        <asp:HiddenField ID="idHidden" runat="server" Value='<%#Eval("Id") %>' />
                                        <asp:HyperLink runat="server" ID="link" CssClass="hastip" ToolTip='<%#Eval("Title") %>'
                                            NavigateUrl='<%#String.Format("~/ShowAd.aspx?id={0}", Eval("id")) %>'><%#Eval("Title").ToString().Substring(0, Eval("Title").ToString().Length > 45 ? 45 : Eval("Title").ToString().Length)%>...</asp:HyperLink>
                                    </p>
                                    <span class="location">
                                        <%# OutputFormatting.AdTypeToString(Eval("AdType")) %></span><br />
                                    <span class="time">Posted:
                                        <%#String.Format("{0:dd/MM/yy}", Eval("DateCreated")) %></span>
                                </div>
                            </ItemTemplate>
                            <FooterTemplate>
                                <div class="clear">
                                </div>
                            </FooterTemplate>
                        </asp:Repeater>
            
            
            <div class="clear">
            </div>
            <div class="viewmore"><a href='search.aspx?c=<%=CategoryDropDown.CurrentCategoryId %>'>View more ads <small>>></small></a></div>
        </div>
        </div>
        <div id="body" style="display:none">
            <div id="search_n_browse">
                <div id="search">
                    <fieldset>
                        <legend>Search</legend>
                        <asp:TextBox ID="CommonSearchTextBox" runat="server" CssClass="search_box" />
                        <uc1:CategoryDropDown ID="CommonCategoryDropDown" runat="server" SelectOptionVisible="false" />
                        <asp:Button ID="SearchButton" runat="server" Text="Search" PostBackUrl="Search.aspx" />
                        <asp:HyperLink ID="AdvancedSearchLink" runat="server" NavigateUrl="AdvancedSearch.aspx">[go to advanced search]</asp:HyperLink>
                    </fieldset>
                </div>
                <div id="browse">
                    <fieldset>
                        <legend>Browse Related Items</legend>
                        <ul>
                            <li>Listings in <strong>
                                <asp:HyperLink ID="CategoryListingsLink" runat="server"></asp:HyperLink></strong></li><li>
                                    <strong class="heading">
                                        <asp:HyperLink ID="MemberListingsLink" runat="server"></asp:HyperLink></strong></li></ul>
                    </fieldset>
                </div>
            </div>
            <div id="content_header">
                <a id="content_start"></a>
                <h3>
                    Actions for this ad</h3>
                
            </div>
            <div id="content">
                <div class="display_left">
                    
                </div>
                <div class="display_right" id="ad_details">
                    
                </div>
            </div>
        </div>
        <div class="hidden">
        <uc1:CategoryDropDown ID="CategoryDropDown" runat="server" SelectOptionVisible="false" />
        <asp:TextBox ID="SearchTermTextBox" runat="server" CssClass="search_box" />
    <uc1:AdvancedSearch ID="AdvancedSearch" runat="server" Visible="False"></uc1:AdvancedSearch>
    </div>
        <asp:ObjectDataSource ID="AdsDataSource" runat="server" TypeName="AspNet.StarterKits.Classifieds.BusinessLogicLayer.AdsDB"
            SelectMethod="GetAdById" OnSelected="AdsDataSource_Selected">
            <SelectParameters>
                <asp:QueryStringParameter Name="adId" DefaultValue="0" QueryStringField="id" Type="Int32">
                </asp:QueryStringParameter>
            </SelectParameters>
        </asp:ObjectDataSource>
        <asp:ObjectDataSource ID="PhotosDataSource" runat="server" SelectMethod="GetPhotosByAdId"
            TypeName="AspNet.StarterKits.Classifieds.BusinessLogicLayer.PhotosDB">
            <SelectParameters>
                <asp:QueryStringParameter Name="adId" DefaultValue="0" QueryStringField="id" Type="Int32">
                </asp:QueryStringParameter>
            </SelectParameters>
        </asp:ObjectDataSource>
    <asp:ObjectDataSource ID="AdSearchDataSource" runat="server" TypeName="AspNet.StarterKits.Classifieds.BusinessLogicLayer.AdsDB"
        SelectMethod="GetActiveAdsByQueryWithPaging" 
        OldValuesParameterFormatString="original_{0}" 
       >
        <SelectParameters>
            <asp:Parameter DefaultValue="10" Name="pageSize" Type="Int32" />
            <asp:ControlParameter ControlID="AdvancedSearch" DefaultValue="1" Name="currentPage"
                PropertyName="currentPage" Type="Int32" />
            <asp:ControlParameter Name="categoryId" DefaultValue="0" Type="Int32" ControlID="CategoryDropDown"
                PropertyName="CurrentCategoryId"></asp:ControlParameter>
            <asp:ControlParameter Name="memberId" ControlID="AdvancedSearch" PropertyName="MemberId"
                Type="Int32" DefaultValue="0" />
            <asp:ControlParameter Name="maxPrice" ControlID="AdvancedSearch" PropertyName="MaximumPrice"
                Type="Decimal" DefaultValue="-1" />
            <asp:ControlParameter Name="searchTerm" DefaultValue="" Type="String" ControlID="SearchTermTextBox"
                PropertyName="Text"></asp:ControlParameter>
            <asp:ControlParameter Name="location" ControlID="AdvancedSearch" PropertyName="Location"
                Type="String" DefaultValue="" />
            <asp:ControlParameter Name="adType" ControlID="AdvancedSearch" PropertyName="AdType"
                Type="Int32" DefaultValue="0" />
            <asp:Parameter Type="Int32" DefaultValue="0" Name="adLevel"></asp:Parameter>
            <asp:ControlParameter Name="dayRange" ControlID="AdvancedSearch" PropertyName="DayRange"
                Type="Int32" DefaultValue="-1" />
            <asp:ControlParameter Name="mustHaveImage" ControlID="AdvancedSearch" PropertyName="MustHavePhotos"
                Type="Boolean" DefaultValue="False" />
           
        </SelectParameters>
    </asp:ObjectDataSource>
    <script language="javascript">
        jQuery('document').ready(function(){
            jQuery('div.small-img a.small-img-switch').click(function(){
                img = jQuery(this);
                mimg = jQuery('div.main-img img:first');
                if(img.attr('href')!= mimg.attr('src'))
                {
                    mimg.fadeOut('fast',function(){
                        mimg.attr('src',img.attr('href'));    
                    });                    
                    mimg.fadeIn();
                } 
                return false;
                
            });
        });
    </script>
    <div id='enlarge_map' style="display:none">
        <div class="overlay">
            <div style="background-color:#000000;opacity: 1;">
            <table cellspacing="0" class="outerImageContainer" style="opacity: 1;">
                <tbody>
                    <tr>
                        <td class="tl">
                        </td>
                        <td class="tc">
                        </td>
                        <td class="tr">
                            <div class="close">
                                <a class="closeLink" id="close_map" href="javascript:void(0);"></a>
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td class="ml">
                        </td>
                        <td class="lightboxFrameBody">
                            <div style="width:750px;height:550px;"
                            <div id='map_holder'>                            
                            </div>
                          
                        </td>
                        <td class="mr">
                        </td>
                    </tr>
                    <tr>
                        <td class="bl">
                        </td>
                        <td class="bc">
                        </td>
                        <td class="br">
                        </td>
                    </tr>
                </tbody>
            </table>
            </div>
        </div>
    </div>
    <script language="javascript" >
     var geocoder;
          var map;
          function initialize() {
            geocoder = new google.maps.Geocoder();
            var latlng = new google.maps.LatLng(-34.397, 150.644);
            var myOptions = {
              zoom: 15,
              center: latlng,
              mapTypeId: google.maps.MapTypeId.ROADMAP
            }
            map = new google.maps.Map(document.getElementById("map_holder"), myOptions);
          }
            
          function codeAddress(address) {                   
            geocoder.geocode( { 'address': address}, function(results, status) {
              if (status == google.maps.GeocoderStatus.OK) {
                map.setCenter(results[0].geometry.location);
                var marker = new google.maps.Marker({
                    map: map,
                    position: results[0].geometry.location,
                    title: jQuery('#show_map').attr('datafld')
                });
              } else {
                alert("Geocode was not successful for the following reason: " + status);
              }
            });
          }
    jQuery('document').ready(function(){
        
        jQuery('#close_map').click(function(){
            jQuery('#enlarge_map').fadeOut();
        });        
        jQuery('#show_map').click(function(){
        jQuery('#enlarge_map .overlay').height(jQuery('body').height());
        jQuery('#enlarge_map .overlay').width(jQuery('body').width());
           if(map==null){
                initialize();         
                codeAddress(jQuery(this).attr('rel'));
                }
            
            jQuery('#enlarge_map').fadeIn();
            
        });
        jQuery(window).scroll(function(){
            jQuery('table.outerImageContainer').css('top',self.pageYOffset + 10);            
            jQuery('table.outerImageContainer .close').css('top',self.pageYOffset + 300);  
            
        });
        
        
    });
    
    </script>
   <script>
        jQuery('document').ready(function(){
            jQuery('a.hastip').cluetip({ dropShadow: false, cluetipClass: 'jtip', showTitle: false, clickThrough: true });
        });
    </script>
    </asp:Content>
